//
//  BVPersonalDataViewController.m
//  XiangYu
//
//  Created by YYKJ on 2017/6/20.
//  Copyright © 2017年 YYKJ. All rights reserved.
//  个人资料修改

#import "BVPersonalDataViewController.h"
#import "BVMineEditorViewController.h"
#import "UITableView+SDAutoTableViewCellHeight.h"

#import "BVMineSingleAlertView.h"
#import "BVAddressAlertView.h"
#import "BVMineTimeAlertView.h"
#import "BVMineProfessionalAlertView.h"
#import "BVTextFieldAlertView.h"

#import "BVMineDataCell.h"
#import "BVMineDataCell2.h"

#import "BVMineModel.h"

#define BUY_MINE_TABLEVIEWCELL1 @"BVMineDataCell1"
#define BUY_MINE_TABLEVIEWCELL2 @"BVMineDataCell2"

@interface BVPersonalDataViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic ,strong) UITableView      *tabView;
@property (nonatomic ,strong) NSArray          *titleArr;
@property (nonatomic ,strong) UIView           *bgViewOne;
@property (nonatomic ,strong) UIImageView      *headerView;


@end

@implementation BVPersonalDataViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor BVBackgroundLightGrayColor]];
    
    [self layoutUI];
    
}

-(void)layoutUI{
    
    [self.view addSubview:self.tabView];
}

#pragma mark -
#pragma mark - UITableViewDelegate,UITableViewDataSource
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *str = @"d声明梦会计师考虑刚万别看过你去乌克兰给你看了人情味了";
    if (indexPath.section == 0) {
        
        return [self.tabView cellHeightForIndexPath:indexPath model:str keyPath:@"text" cellClass:[BVMineDataCell2 class] contentViewWidth:ScreenW];
        
    }else{
        return 50;
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [UIView new];
    [view setBackgroundColor:[UIColor BVBackgroundLightGrayColor]];
    return view;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.titleArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    NSMutableArray *arr = self.titleArr[section];
    return arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    BVMineModel *model = [BVMineModel shareTools];
    
    if (indexPath.section == 0) {
        
        BVMineDataCell2 *cell = [tableView dequeueReusableCellWithIdentifier:BUY_MINE_TABLEVIEWCELL2];
        [cell.titleLb setText:[NSString stringWithFormat:@"%@",self.titleArr[indexPath.section][indexPath.row][@"titel"]]];
        cell.text = @"d声明梦会计师考虑刚万别看过你去乌克兰给你看了人情味了";
        return cell;
        
    }
    else{
        BVMineDataCell *cell = [tableView dequeueReusableCellWithIdentifier:BUY_MINE_TABLEVIEWCELL1];
        
        [cell.titleLb setText:[NSString stringWithFormat:@"%@",self.titleArr[indexPath.section][indexPath.row][@"titel"]]];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.index = indexPath;
        cell.model = model;
        
        return cell;
    }
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    BVMineModel *model = [BVMineModel shareTools];
    
    BVMineDataCell *cell;
    if (indexPath.section == 1) {
         cell = [self.tabView cellForRowAtIndexPath:indexPath];
    }
    
    NSString *str = [NSString stringWithFormat:@"%@",self.titleArr[indexPath.section][indexPath.row][@"titel"]];
    
    if (indexPath.section == 0 ) {
        if (self.monologueBlock) {
            self.monologueBlock(str);
        }
        
    }else if (indexPath.section == 1){
        
        switch (indexPath.row) {
            case 0:{
                BVTextFieldAlertView *alertView = [[BVTextFieldAlertView alloc]init];
                [alertView showMKPAlertView];
                alertView.AlertResult = ^(NSString *str) {
                    model.nickName = [str mutableCopy];
                    [self.tabView reloadData];
                };
            }
                break;
            case 1:{
                BVMineSingleAlertView *alertView = [[BVMineSingleAlertView alloc]init:Sex];
                [alertView showMKPAlertView];
                alertView.AlertResult = ^(NSString *str) {
                    model.sex = [str mutableCopy];
                    [self.tabView reloadData];
                };
            }
                break;
            case 2:{
                BVMineSingleAlertView *alertView = [[BVMineSingleAlertView alloc]init:height];
                [alertView showMKPAlertView];
                alertView.AlertResult = ^(NSString *str) {
                    model.height = [str mutableCopy];
                    [self.tabView reloadData];
                };
            }
                break;
            case 3:{
                BVMineSingleAlertView *alertView = [[BVMineSingleAlertView alloc]init:Education];
                [alertView showMKPAlertView];
                alertView.AlertResult = ^(NSString *str) {
                    model.education = [str mutableCopy];
                    [self.tabView reloadData];
                };
            }
                break;
            case 4:{
                BVMineProfessionalAlertView *alertView = [[BVMineProfessionalAlertView alloc]init];
                [alertView showMKPAlertView];
                
            }
                break;
            case 5:{
                BVMineSingleAlertView *alertView = [[BVMineSingleAlertView alloc]init:MonthlySalary];
                [alertView showMKPAlertView];
                alertView.AlertResult = ^(NSString *str) {
                    model.monthlySalary = [str mutableCopy];
                    [self.tabView reloadData];
                };
                
            }
                break;
            case 6:{
                
                BVAddressAlertView *alertView = [[BVAddressAlertView alloc]init];
                [alertView showMKPAlertView];
                alertView.AlertResult = ^(NSString *str) {
                    model.address = [str mutableCopy];
                    [self.tabView reloadData];
                };
            }
                break;
            case 7:{
                
                BVMineTimeAlertView *timeAlert = [[BVMineTimeAlertView alloc]init];
                [timeAlert showMKPAlertView];
                timeAlert.AlertResult = ^(NSString *str) {
                    model.dateBirth = [str mutableCopy];
                    [self.tabView reloadData];
                };
            }
                break;
            default:
                break;
        }
    }else if (indexPath.section == 2){
        switch (indexPath.row) {
            case 0:{
                BVMineSingleAlertView *alertView = [[BVMineSingleAlertView alloc]init:CompanyType];
                [alertView showMKPAlertView];
                alertView.AlertResult = ^(NSString *str) {
                    model.companyType = [str mutableCopy];
                    [self.tabView reloadData];
                };
            }
                break;
            case 1:{
                BVMineSingleAlertView *alertView = [[BVMineSingleAlertView alloc]init:WorkingState];
                [alertView showMKPAlertView];
                alertView.AlertResult = ^(NSString *str) {
                    model.workingState = [str mutableCopy];
                    [self.tabView reloadData];
                };
            }
                break;
            case 2:{
                BVMineSingleAlertView *alertView = [[BVMineSingleAlertView alloc]init:Exercise];
                [alertView showMKPAlertView];
                alertView.AlertResult = ^(NSString *str) {
                    model.exercise = [str mutableCopy];
                    [self.tabView reloadData];
                };
            }
                break;
            case 3:{
                BVMineSingleAlertView *alertView = [[BVMineSingleAlertView alloc]init:Smoke];
                [alertView showMKPAlertView];
                alertView.AlertResult = ^(NSString *str) {
                    model.smoke = [str mutableCopy];
                    [self.tabView reloadData];
                };
            }
                break;
            case 4:{
                BVMineSingleAlertView *alertView = [[BVMineSingleAlertView alloc]init:Drink];
                [alertView showMKPAlertView];
                alertView.AlertResult = ^(NSString *str) {
                    model.drink = [str mutableCopy];
                    [self.tabView reloadData];
                };
            }
                break;
            case 5:{
                BVMineSingleAlertView *alertView = [[BVMineSingleAlertView alloc]init:LiveParents];
                [alertView showMKPAlertView];
                alertView.AlertResult = ^(NSString *str) {
                    model.liveParents = [str mutableCopy];
                    [self.tabView reloadData];
                };
            }
                break;
            default:
                break;
        }
    }
    
}

-(UITableView *)tabView{
    if (!_tabView) {
        self.tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH-150-64-40) style:UITableViewStylePlain];
        [self.tabView setDelegate:self];
        [self.tabView setDataSource:self];
        [self.tabView setBackgroundColor:[UIColor clearColor]];
        [self.tabView setTableFooterView:[UIView new]];
        [self.tabView setShowsVerticalScrollIndicator:NO];
        [self.tabView registerClass:[BVMineDataCell class] forCellReuseIdentifier:BUY_MINE_TABLEVIEWCELL1];
        [self.tabView registerClass:[BVMineDataCell2 class] forCellReuseIdentifier:BUY_MINE_TABLEVIEWCELL2];
        
    }
    return _tabView;
}

-(NSArray *)titleArr{
    if (!_titleArr) {
        self.titleArr = [NSArray arrayWithObjects:
                         @[@{@"titel":@"内心独白"}],
                         @[@{@"titel":@"*昵称"},
                           @{@"titel":@"*性别"},
                           @{@"titel":@"*身高"},
                           @{@"titel":@"*学历"},
                           @{@"titel":@"*职业"},
                           @{@"titel":@"*月薪"},
                           @{@"titel":@"*所在地"},
                           @{@"titel":@"*出生日期"}],
                         @[@{@"titel":@"公司类型"},
                           @{@"titel":@"工作状态"},
                           @{@"titel":@"锻炼习惯"},
                           @{@"titel":@"是否抽烟"},
                           @{@"titel":@"是否酗酒"},
                           @{@"titel":@"是否和父母同住"}],nil];
    }
    return _titleArr;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
